package com.example.qingyiapp.ui.activity.fragment.fragment_FindUI.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.qingyiapp.R;
import com.example.qingyiapp.service.entify.FindChoicenessTwoBean;
import com.example.qingyiapp.service.entify.FindWaitYouBean;

import java.util.ArrayList;

/**
 * Creadted by Met·Wang on 2019/9/18 14:36
 * Describe: NullPointerException Write
 */
public class FindSquareWaityouRecyclerAdapter extends RecyclerView.Adapter<FindSquareWaityouRecyclerAdapter.VHolder> {


    ArrayList<FindWaitYouBean.DataBean> list;
    Context context;

    OnItemClick onClick;

    public void setOnClick(OnItemClick onClick) {
        this.onClick = onClick;
    }

    public interface  OnItemClick{
        void onClick(int i);
    }


    public FindSquareWaityouRecyclerAdapter(ArrayList<FindWaitYouBean.DataBean> list, Context context) {
        this.list = list;
        this.context = context;
    }


    @NonNull
    @Override
    public VHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.fragment_find_square_waityou_item, null);

        return new VHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull VHolder vHolder, final int i) {

        FindWaitYouBean.DataBean dataBean = list.get(i);
        String imagecover = dataBean.getImagecover();


        Glide.with(context).load(dataBean.getUser().getUsercover()+"").apply(RequestOptions.circleCropTransform()).into(vHolder.icon);
        vHolder.userName.setText(dataBean.getUser().getName()+"");

        String time = dataBean.getTime();
        String[] s = time.split(" ");
        vHolder.time.setText(s[0]+"");
        vHolder.title.setText(dataBean.getTitle()+"");

        if(imagecover.equals("")){
            vHolder.recyclerViewNo.setVisibility(View.VISIBLE);
            vHolder.recyclerViewYes.setVisibility(View.GONE);
            vHolder.content2.setText(Html.fromHtml(dataBean.getContent()+""));


        }else {
            vHolder.recyclerViewYes.setVisibility(View.VISIBLE);
            vHolder.recyclerViewNo.setVisibility(View.GONE);
            vHolder.content1.setText(Html.fromHtml(dataBean.getContent()+""));
            Glide.with(context).load(imagecover).into(vHolder.image);
        }

        vHolder.relativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClick.onClick(i);
            }
        });


    }



    @Override
    public int getItemCount() {
        return list.size();
    }

    class VHolder extends RecyclerView.ViewHolder{

        ImageView icon,image;
        TextView title,userName,content1,content2,time;
        RelativeLayout recyclerViewNo,recyclerViewYes;
        RelativeLayout relativeLayout;




        public VHolder(@NonNull View itemView) {
            super(itemView);
            icon=itemView.findViewById(R.id.find_square_waityou_item_Icon);
            image=itemView.findViewById(R.id.find_square_waityou_item_image1);
            title=itemView.findViewById(R.id.find_square_waityou_item_title);
            content2=itemView.findViewById(R.id.find_square_waityou_item_content2);
            content1=itemView.findViewById(R.id.find_square_waityou_item_content1);
            userName=itemView.findViewById(R.id.find_square_waityou_item_userName);
            time=itemView.findViewById(R.id.find_square_waityou_item_time);
            recyclerViewNo=itemView.findViewById(R.id.find_square_waityou_item_NoImager);
            recyclerViewYes=itemView.findViewById(R.id.find_square_waityou_item_YesImager);
            relativeLayout=itemView.findViewById(R.id.waityou_All);
        }
    }

}
